#pragma once
#include <GRendererInfra\GRiObj.h>
#include "GRTXRay.h"

// 所以能被射线相交的实体
class GRTXObject
{
public:
	virtual bool IsLight()const = 0;
	// 返回对光源的采样点和pdf.
	virtual void SampleLight(GRiVertex& samplePos, float& pdf)const = 0;
	float GetArea() const { return Area; }

	virtual HitInfo Interset(const GRTXRay& ray) const = 0;
	

	GRiBounds3Box GetBox()const { return Box; }
protected:
	float Area = 0;
	GRiBounds3Box Box;
};
inline HitInfo IntersectSet(const GRTXRay& ray, const std::vector<GSPtr<GRTXObject>>& objs)
{
	HitInfo info;
	for (auto& tri : objs)
	{
		auto triInfo = tri->Interset(ray);

		if (triInfo.t <= info.t)
		{
			info = triInfo;
		}
	}
	return info;
}
